{ INFORMATICS.MCCME.RU
  Problem statement: http://informatics.mccme.ru/moodle/mod/statements/view3.php?chapterid=1592
  Verdict: Accepted
}
uses
	SysUtils, Math;
 
var 
	i,j,n,m,q,ans,x,y:longint;
	a:array[0..110,0..110] of longint;
 
begin
reset(input,'input.txt');
rewrite(output,'output.txt');
read(n,m);
for i:=1 to n do
	for j:=1 to m do
		read(a[i][j]);
read(q);
ans:=0;
for i:=1 to q do begin
	read(x,y);
	inc(ans,a[x][y]);
	a[x][y]:=0;
end;
write(ans);
end.